const totalNameForm = {
	name: '姓名',
	identityCard: '身份证号',
	tel: '联系电话',
	sex: '性别',
	birthday: '出生日期',
	maritalStatus: '婚姻情况',
	registeredPermanentResidence: '户籍所在地',
	residentialAddress: '居住地址',
	urgentName: '紧急联络人',
	urgentTel: '紧急联络人电话',
	local:'应聘地点',
	position: '应聘岗位',
	salaryExpectation: '期望薪资',
	fastestWorkTime: '最快到岗时间',
	learnStartTime: '最高学历开始时间',
	learnEndTime: '最高学历毕业时间',
	schoolName: '学校名称',
	examinationType: '统考/自考',
	educationList: '学历',
	major: '专业',
	graduateType: '毕业'
};
app = new Vue({
	el: "#app",
	data() {
		return {
			showPicker: false,
			showLocalPicker: false,
			columns: POSITIONTYPE,
			localcolumns: LOCALTYPE,
			submitDisable: false,
			timeValueTemp: '',
			timeValueStart: '请选择时间',
			timeValueEnd: '请选择时间',
			timeValueFast: '请选择时间',
			timeValueBirthday: '请选择时间',
			temp: '',
			isLoadingShow: true,
			currentDate: new Date(),
			className: '',
			showbirthday: false,
			showfastest: false,
			showstart: false,
			showend: false,
			minbirthDate: new Date(1975, 0, 1),
			minDate: new Date(1980, 0, 1),
			minfastDate: new Date(),
			maxDate: new Date(2030, 0, 31),
			active: 0,
			activeName: '1',
			deepForm:{
				
			},
			totalForm: {
				name: '',
				identityCard: '',
				tel: '',
				sex: '男',
				birthday: '',
				maritalStatus: '已婚',
				registeredPermanentResidence: '',
				residentialAddress: '',
				urgentName: '',
				urgentTel: '',
				local:'',
				position: '',
				salaryExpectation: '',
				fastestWorkTime: '',
				learnStartTime: '',
				learnEndTime: '',
				schoolName: '',
				examinationType: '统考',
				educationList: '',
				major: '',
				graduateType: '毕业',
				
			},

		}
	},
	methods: {
		async add() {
			const regtel = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
			const regID = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;
			const regsalary = /^\d{5}$|^\d{4}$/;
			for (let item in this.totalForm) {
				if (this.totalForm[item] == '') {
					console.log(item)
					this.$toast(totalNameForm[item] + "不能为空");
					return false;
				}
			}
			if(this.totalForm.tel===this.totalForm.urgentTel){
					this.$toast("个人手机号和紧急联络人手机号一样,请重新输入");
					return false;
			}
			if(this.totalForm.name===this.totalForm.urgentName){
					this.$toast("姓名和紧急联络人姓名一样,请重新输入");
					return false;
			}
			try {
				this.submitDisable = true;
				let res = await axios.put('api/registration/add', this.totalForm);
				if (res.code === 200) {
					this.$toast("添加成功");
				} else {
					this.submitDisable = false;
					this.$toast("后端异常");
				}
			} catch (e) {
				this.submitDisable = false;
				this.$toast("系统异常");
			}
		},
		onConfirm(value) {
			this.totalForm.position = value;
			this.showPicker = false;
		},
		onLocalConfirm(value) {
			this.totalForm.local = value;
			this.showLocalPicker = false;
		},
		showPopup() {
			this.isLoadingShow = true
			setTimeout(() => {
				this.isLoadingShow = false
			}, 500)
		},
		showPopupStart() {
			this.showstart = true
			this.showPopup()
		},
		showPopupEnd() {
			this.showend = true
			this.showPopup()
		},
		showPopupFast() {
			this.showfastest = true
			this.showPopup()
		},
		showPopupBirthday() {
			this.showbirthday = true
			this.showPopup()
		},
		// 确认选择的时间
		confirmPicker(val) {
			let year = val.getFullYear()
			let month = val.getMonth() + 1
			let day = val.getDate()
			if (month >= 1 && month <= 9) {
				month = `0${month}`
			}
			if (day >= 1 && day <= 9) {
				day = `0${day}`
			}
			this.className = 'timeClass'
			this.timeValueTemp = `${year}-${month}-${day}`
			this.temp = `${year}-${month}-${day}`
		},
		confirmPickerStart(val) {
			this.confirmPicker(val);
			this.totalForm.learnStartTime = this.temp
			this.timeValueStart = this.timeValueTemp
			this.showstart = false
		},
		confirmPickerEnd(val) {
			this.confirmPicker(val);
			this.totalForm.learnEndTime = this.temp
			this.timeValueEnd = this.timeValueTemp
			this.showend = false
		},
		confirmPickerFast(val) {
			this.confirmPicker(val);
			this.totalForm.fastestWorkTime = this.temp
			this.timeValueFast = this.timeValueTemp
			this.showfastest = false
		},
		confirmPickerBirthday(val) {
			this.confirmPicker(val);
			this.totalForm.birthday = this.temp
			this.timeValueBirthday = this.timeValueTemp
			this.showbirthday = false
		},
		trans(){
			this.totalForm.identityCard = this.deepForm.identityCard
			this.totalForm.name = this.deepForm.name
			this.totalForm.sex = this.deepForm.sex
			this.totalForm.birthday = this.deepForm.birthday
			this.totalForm.maritalStatus = this.deepForm.maritalStatus
			this.totalForm.tel = this.deepForm.tel
			this.totalForm.registeredPermanentResidence = this.deepForm.registeredPermanentResidence
			this.totalForm.residentialAddress = this.deepForm.residentialAddress
			this.totalForm.urgentName = this.deepForm.urgentName
			this.totalForm.urgentTel = this.deepForm.urgentTel	
			this.totalForm.local = this.deepForm.local
			this.totalForm.position = this.deepForm.position
			this.totalForm.salaryExpectation = this.deepForm.salaryExpectation
			this.totalForm.fastestWorkTime = this.deepForm.fastestWorkTime
			this.totalForm.learnStartTime = this.deepForm.learnStartTime
			this.totalForm.learnEndTime = this.deepForm.learnEndTime
			this.totalForm.schoolName = this.deepForm.schoolName
			this.totalForm.examinationType = this.deepForm.examinationType
			this.totalForm.educationList = this.deepForm.educationList
			this.totalForm.major = this.deepForm.major
			this.totalForm.graduateType = this.deepForm.graduateType
		},
		async findexist() {
			try {
				
				let res = await axios.post('api/registration/query', this.totalForm);
				console.log(res)
				if (res.code === 200) {
					this.submitDisable = true;
					if (res.total == 0) {
						this.submitDisable = false;
					} else if (res.total == 1) {
						console.log(res.data[0])
						this.deepForm = deepCopy(res.data[0])
						this.trans()
						this.timeValueBirthday = res.data[0].birthday
						this.timeValueFast = res.data[0].fastestWorkTime
						this.timeValueLearnEnd = res.data[0].learnStartTime
						this.timeValueLearnStart = res.data[0].learnEndTime
					}else if (res.total > 1) {
						this.totalForm = deepCopy(res.data[0])
						this.timeValueBirthday = res.data[0].birthday
						this.timeValueFast = res.data[0].fastestWorkTime
						this.timeValueLearnEnd = res.data[0].learnStartTime
						this.timeValueLearnStart = res.data[0].learnEndTime
					}
				} else {
					this.$toast("后端异常");
				}
			} catch (e) {
				this.$toast("系统异常");
			}
		}
	},
	async mounted() {

	}
});
